<?php

namespace App\Jobs;

use App\Models\GoldRecord;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Services\MakeGoldRecord\MakeGoldRecord;
use App\Services\SettleGoldRecordReselling\SettleGoldRecordReselling;

class MakeGoldRecordJob implements ShouldQueue
{
	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

	public int $uid;
	public string $unpaidCacheId;

	public function __construct($uid, $unpaidCacheId)
	{
		$this->uid = $uid;
		$this->unpaidCacheId = $unpaidCacheId;
	}

	public function handle()
	{
        /**
         * @var GoldRecord $record
         */

		$record = app(MakeGoldRecord::class, [
			'user' => $this->uid,
			'unpaidCacheId' => $this->unpaidCacheId
		])->make();

		if ($record) {
            app(SettleGoldRecordReselling::class, ['record' => $record])->run();
		}
	}
}
